package com.dlyk.service.impl;

import com.dlyk.constant.Constants;
import com.dlyk.mapper.TActivityMapper;
import com.dlyk.mapper.TActivityRemarkMapper;
import com.dlyk.model.TActivity;
import com.dlyk.model.TActivityRemark;
import com.dlyk.model.TUser;
import com.dlyk.query.ActivityRemarkQuery;
import com.dlyk.query.BaseQuery;
import com.dlyk.service.ActivityRemarkService;
import com.dlyk.util.JWTUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @description:
 * @author: ajie
 * @date: 2024/7/23 18:14:49
 * @version: 1.0
 */
@Service
public class ActivityRemarkServiceImpl implements ActivityRemarkService {

    @Resource
    private TActivityRemarkMapper tActivityRemarkMapper;

    @Override
    public int saveActivityRemark(ActivityRemarkQuery activityRemarkQuery) {

        TActivityRemark tActivityRemark = new TActivityRemark();

        BeanUtils.copyProperties(activityRemarkQuery,tActivityRemark);

        tActivityRemark.setCreateTime(new Date());//创建时间

        ///登陆人的id
        Integer loginUserId = JWTUtils.parseJWTByUserId(activityRemarkQuery.getToken());
        tActivityRemark.setCreateBy(loginUserId);//创建人
        return tActivityRemarkMapper.insertSelective(tActivityRemark);
    }

    @Override
    public PageInfo<TActivityRemark> getActivityRemarkByPage(Integer current,ActivityRemarkQuery activityRemarkQuery ) {
        //设置PageHelper的分页参数
        PageHelper.startPage(current, Constants.PAGE_SIZE);
        //查询
        List<TActivityRemark> list = tActivityRemarkMapper.selectActivityRemarkByPage(activityRemarkQuery);
        //封装分页参数到PageInfo
        PageInfo<TActivityRemark> info = new PageInfo<>(list);
        return info;
    }

    @Override
    public TActivityRemark getActivityRemarkById(Integer id) {
        return tActivityRemarkMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateActivityRemark(ActivityRemarkQuery activityRemarkQuery) {
        TActivityRemark tActivityRemark = new TActivityRemark();

        BeanUtils.copyProperties(activityRemarkQuery,tActivityRemark);

        tActivityRemark.setEditTime(new Date());//编辑时间

        ///登陆人的id
        Integer loginUserId = JWTUtils.parseJWTByUserId(activityRemarkQuery.getToken());
        tActivityRemark.setEditBy(loginUserId);//编辑人
        return tActivityRemarkMapper.updateByPrimaryKeySelective(tActivityRemark);
    }

    @Override
    public int delActivityRemarkById(Integer id) {
        //逻辑删除
        TActivityRemark tActivityRemark = new TActivityRemark();
        tActivityRemark.setId(id);
        tActivityRemark.setDeleted(1);//删除状态（null或者0正常，1删除）
        return tActivityRemarkMapper.updateByPrimaryKeySelective(tActivityRemark);
    }


}
